﻿using SuperSocket.ProtoBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperWeight
{
    public class WeightPackageInfo : IPackageInfo<string>, IPackageInfo
    {
        /// <summary>
        /// 编码规则
        /// </summary>
        private Encoding m_Encoding = Encoding.ASCII;

        /// <summary>
        /// 构造函数
        /// </summary>
        public WeightPackageInfo(byte[] byte_Body, Encoding encoding)
        {
            this.Byte_Body = byte_Body;
            this.m_Encoding = encoding;
        }
        /// <summary>
        /// 反馈内容头
        /// </summary>
        public string Key
        {
            get
            {
                if (Byte_Body != null && Byte_Body.Length > 6)
                {
                    return m_Encoding.GetString(this.Byte_Body.Take(6).ToArray());
                }
                return "Error";
            }
        }
        /// <summary>
        /// 反馈内容头
        /// <para>电子秤反馈头</para>
        /// </summary>
        public string Header
        {
            get
            {
                return Key;
            }
        }
        /// <summary>
        /// 正或负
        /// </summary>
        public string PlusOrMinux
        {
            get
            {
                if (Byte_Body != null && Byte_Body.Length > 7)
                {
                    return m_Encoding.GetString(this.Byte_Body.Skip(6).Take(1).ToArray());
                }
                return "Error";
            }
        }

        /// <summary>
        /// 重量信息
        /// </summary>
        public string Weight
        {
            get
            {
                if (Byte_Body != null && Byte_Body.Length > 16)
                {
                    return m_Encoding.GetString(this.Byte_Body.Skip(8).Take(8).ToArray());
                }
                return "Error";
            }
        }
        /// <summary>
        /// 单位符号
        /// </summary>
        public string UnitSysbol
        {
            get
            {
                if (Byte_Body != null && Byte_Body.Length > 20)
                {
                    return m_Encoding.GetString(this.Byte_Body.Skip(17).Take(3).ToArray());
                }
                return "Error";
            }
        }
        /// <summary>
        /// 整体反馈内容
        /// </summary>
        public string Body
        {
            get
            {
                if (Byte_Body != null && Byte_Body.Length > 0)
                {
                    return m_Encoding.GetString(this.Byte_Body);
                }
                return "Error";
            }
        }
        /// <summary>
        /// 整体反馈内容的Byte形式
        /// </summary>
        public byte[] Byte_Body { get; set; }

    }
}
